package com.jinbaoty.recyclebins.command;

import java.util.HashMap;
import java.util.Map;

public class CommandOrder {

    //一号门
    public static CommandParam DOOR1_OPEN = CommandParam.builder().commandTag("open").commandName("1号门开").commandVal((byte)0x01).successMsg("正在进行回收，请稍等片刻。。。").errorMsg("设备故障，回收门无法开启").readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam DOOR1_CLOSE = CommandParam.builder().commandTag("close").commandName("1号门关").commandVal((byte)0x02).readTimeout(1000).readRepeat(1).build();
    public static CommandParam DOOR1_WEIGHT = CommandParam.builder().commandTag("weight").commandName("1号门称重").commandVal((byte)0x21).readTimeout(2000).returnType(CommandParam.RETURN_FORCE).errorMsg("称重故障").readRepeat(3).writeRepeat(2).build();
    public static CommandParam DOOR1_IS_FULL = CommandParam.builder().commandTag("isfull").commandName("1号回收箱是否已满").commandVal((byte)0xc1).readTimeout(1000).successVal("t").errorMsg("回收箱已满").returnType(CommandParam.RETURN_FORCE).readRepeat(2).build();

    public static CommandParam WAITING = CommandParam.builder().commandTag("confirm").commandName("等待用户确认").commandVal((byte)CommandParam.WAITING_TAG).successMsg("结束投递").errorMsg("取消投递").build();

    public static CommandParam[] door1Orders = new CommandParam[]{DOOR1_IS_FULL,DOOR1_OPEN,WAITING,DOOR1_CLOSE,DOOR1_WEIGHT};


    //二号门
    public static CommandParam DOOR2_OPEN = CommandParam.builder().commandTag("open").commandName("2号门开").commandVal((byte)0x03).successMsg("正在进行回收，请稍等片刻。。。").errorMsg("设备故障，回收门无法开启").readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam DOOR2_CLOSE = CommandParam.builder().commandTag("close").commandName("2号门关").commandVal((byte)0x04).readTimeout(1000).readRepeat(1).build();
    public static CommandParam DOOR2_WEIGHT = CommandParam.builder().commandTag("weight").commandName("2号门称重").commandVal((byte)0xaa).readTimeout(2000).returnType(CommandParam.RETURN_FORCE).errorMsg("称重故障").readRepeat(3).writeRepeat(2).build();
    public static CommandParam DOOR2_IS_FULL = CommandParam.builder().commandTag("isfull").commandName("2号回收箱是否已满").commandVal((byte)0xc2).readTimeout(1000).successVal("t").errorMsg("回收箱已满").returnType(CommandParam.RETURN_FORCE).readRepeat(2).build();

    public static CommandParam[] door2Orders = new CommandParam[]{DOOR2_IS_FULL,DOOR2_OPEN,WAITING,DOOR2_CLOSE,DOOR2_WEIGHT};

    //三号门
    public static CommandParam DOOR3_OPEN = CommandParam.builder().commandTag("open").commandName("3号门开").commandVal((byte)0x11).successMsg("正在进行回收，请稍等片刻。。。").errorMsg("设备故障，回收门无法开启").readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam DOOR3_CLOSE = CommandParam.builder().commandTag("close").commandName("3号门关").commandVal((byte)0x12).readTimeout(1000).readRepeat(1).build();
    public static CommandParam DOOR3_WEIGHT = CommandParam.builder().commandTag("weight").commandName("3号门称重").commandVal((byte)0xab).readTimeout(2000).returnType(CommandParam.RETURN_FORCE).errorMsg("称重故障").readRepeat(3).writeRepeat(2).build();
    public static CommandParam DOOR3_IS_FULL = CommandParam.builder().commandTag("isfull").commandName("3号回收箱是否已满").commandVal((byte)0xc3).readTimeout(1000).successVal("t").errorMsg("回收箱已满").returnType(CommandParam.RETURN_FORCE).readRepeat(2).build();

    public static CommandParam[] door3Orders = new CommandParam[]{DOOR3_IS_FULL,DOOR3_OPEN,WAITING,DOOR3_CLOSE,DOOR3_WEIGHT};


    //四号门
    public static CommandParam DOOR4_OPEN = CommandParam.builder().commandTag("open").commandName("4号门开").commandVal((byte)0x13).successMsg("正在进行回收，请稍等片刻。。。").errorMsg("设备故障，回收门无法开启").readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam DOOR4_CLOSE = CommandParam.builder().commandTag("close").commandName("4号门关").commandVal((byte)0x14).readTimeout(1000).readRepeat(1).build();

    public static CommandParam DOOR4_WEIGHT = CommandParam.builder().commandTag("weight").commandName("4号门称重").commandVal((byte)0x22).readTimeout(2000).returnType(CommandParam.RETURN_FORCE).errorMsg("称重故障").readRepeat(3).writeRepeat(2).build();
    public static CommandParam DOOR4_IS_FULL = CommandParam.builder().commandTag("isfull").commandName("4号回收箱是否已满").commandVal((byte)0xc4).readTimeout(1000).successVal("t").errorMsg("回收箱已满").returnType(CommandParam.RETURN_FORCE).readRepeat(2).build();

    public static CommandParam[] door4Orders = new CommandParam[]{DOOR4_IS_FULL,DOOR4_OPEN,WAITING,DOOR4_CLOSE,DOOR4_WEIGHT,DOOR4_CLOSE};


    //五号门（口罩机）
    public static CommandParam DOOR5_OPEN = CommandParam.builder().commandTag("open").commandName("5号门开").commandVal((byte)0x01).successMsg("正在进行回收，请稍等片刻。。。").errorMsg("设备故障，回收门无法开启").readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam DOOR5_CLOSE = CommandParam.builder().commandTag("close").commandName("5号门关").commandVal((byte)0x02).readTimeout(1000).readRepeat(1).build();
    public static CommandParam DOOR5_WEIGHT = CommandParam.builder().commandTag("weight").commandName("5号门称重").commandVal((byte)0x21).readTimeout(2000).returnType(CommandParam.RETURN_FORCE).errorMsg("称重故障").readRepeat(3).writeRepeat(2).build();
    public static CommandParam DOOR5_IS_FULL = CommandParam.builder().commandTag("isfull").commandName("5号回收箱是否已满").commandVal((byte)0xae).readTimeout(1000).successVal("t").errorMsg("回收箱已满").returnType(CommandParam.RETURN_FORCE).readRepeat(2).build();

    public static CommandParam[] door5Orders = new CommandParam[]{DOOR5_IS_FULL,DOOR5_OPEN,WAITING,DOOR5_CLOSE,DOOR5_WEIGHT};


    public static CommandParam[][] orderSet = new CommandParam[][]{door1Orders,door2Orders,door3Orders,door4Orders};

    public static CommandParam  sterilize_open = CommandParam.builder().commandTag("sterilize_open").commandName("消杀开").commandVal((byte)0xc4).readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();
    public static CommandParam  sterilize_close = CommandParam.builder().commandTag("sterilize_close").commandName("消杀关").commandVal((byte)0xc5).readTimeout(1000).writeGap(200).returnType(CommandParam.RETURN_FORCE).successVal("ok").readRepeat(1).build();

    public static Map<String,CommandParam> commandParamMap = new HashMap<>();

    static{
        for(int i=0;i<orderSet.length;i++){
            CommandParam[] commandParams = orderSet[i];
            for(CommandParam commandParam:commandParams){
                commandParamMap.put((i+1)+"_"+commandParam.getCommandTag(),commandParam);
            }
        }
        commandParamMap.put("_"+sterilize_open.getCommandTag(),sterilize_open);
        commandParamMap.put("_"+sterilize_close.getCommandTag(),sterilize_close);
    }

}
